﻿using SuperLottery.Datas.DbModels;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;

namespace SuperLottery.AdminPortal.Models
{
	public class DrawModel
	{
		public long Id { get; set; }

		[Display(Name = "彩种")]
		[Required]
		public string IssuerGame { get; set; }

		[Display(Name = "类型")]
		public string Issuer { get; set; }

		[Display(Name = "玩法")]
		public string Game { get; set; }

		[Display(Name = "开奖日期")]
		public DateTime DrawDate { get; set; }

		[Display(Name = "期号")]
		[Required]
		public string IssueNumber { get; set; }

		[Display(Name = "基本号码")]
		[Required]
		public string Numbers { get; set; }

		[Display(Name = "特殊号码")]
		[Required]
		public string BonusNumbers { get; set; }

		[Display(Name = "本期销售")]
		public decimal SalesAmount { get; set; }

		[Display(Name = "累计奖金")]
		public decimal CumulativeAmount { get; set; }

		public string Award1Name { get; set; }

		public int Award1NumberOfWinners { get; set; }

		public int Award1MoneyPerWinner { get; set; }

		public string Award2Name { get; set; }

		public int Award2NumberOfWinners { get; set; }

		public int Award2MoneyPerWinner { get; set; }

		public string Award3Name { get; set; }

		public int Award3NumberOfWinners { get; set; }

		public int Award3MoneyPerWinner { get; set; }

		public string Award4Name { get; set; }

		public int Award4NumberOfWinners { get; set; }

		public int Award4MoneyPerWinner { get; set; }

		public string Award5Name { get; set; }

		public int Award5NumberOfWinners { get; set; }

		public int Award5MoneyPerWinner { get; set; }

		public string Award6Name { get; set; }

		public int Award6NumberOfWinners { get; set; }

		public int Award6MoneyPerWinner { get; set; }

		public string Award7Name { get; set; }

		public int Award7NumberOfWinners { get; set; }

		public int Award7MoneyPerWinner { get; set; }

		public string GetIssuerGame()
		{
			return Issuer + "-" + Game;
		}

		public List<WinningDetail> GetWinningDetails()
		{
			List<WinningDetail> details = new List<WinningDetail>();
			if (!String.IsNullOrWhiteSpace(this.Award1Name))
			{
				WinningDetail detail = new WinningDetail();
				detail.Award = this.Award1Name;
				detail.Serial = 1;
				detail.NumberOfWinners = this.Award1NumberOfWinners;
				detail.MoneyPerWinner = this.Award1MoneyPerWinner;
				details.Add(detail);
			}
			if (!String.IsNullOrWhiteSpace(this.Award2Name))
			{
				WinningDetail detail = new WinningDetail();
				detail.Award = this.Award2Name;
				detail.Serial = 2;
				detail.NumberOfWinners = this.Award2NumberOfWinners;
				detail.MoneyPerWinner = this.Award2MoneyPerWinner;
				details.Add(detail);
			}
			if (!String.IsNullOrWhiteSpace(this.Award3Name))
			{
				WinningDetail detail = new WinningDetail();
				detail.Award = this.Award3Name;
				detail.Serial = 3;
				detail.NumberOfWinners = this.Award3NumberOfWinners;
				detail.MoneyPerWinner = this.Award3MoneyPerWinner;
				details.Add(detail);
			}
			if (!String.IsNullOrWhiteSpace(this.Award4Name))
			{
				WinningDetail detail = new WinningDetail();
				detail.Award = this.Award4Name;
				detail.Serial = 4;
				detail.NumberOfWinners = this.Award4NumberOfWinners;
				detail.MoneyPerWinner = this.Award4MoneyPerWinner;
				details.Add(detail);
			}
			if (!String.IsNullOrWhiteSpace(this.Award5Name))
			{
				WinningDetail detail = new WinningDetail();
				detail.Award = this.Award5Name;
				detail.Serial = 5;
				detail.NumberOfWinners = this.Award5NumberOfWinners;
				detail.MoneyPerWinner = this.Award5MoneyPerWinner;
				details.Add(detail);
			}
			if (!String.IsNullOrWhiteSpace(this.Award6Name))
			{
				WinningDetail detail = new WinningDetail();
				detail.Award = this.Award6Name;
				detail.Serial = 6;
				detail.NumberOfWinners = this.Award6NumberOfWinners;
				detail.MoneyPerWinner = this.Award6MoneyPerWinner;
				details.Add(detail);
			}
			if (!String.IsNullOrWhiteSpace(this.Award7Name))
			{
				WinningDetail detail = new WinningDetail();
				detail.Award = this.Award7Name;
				detail.Serial = 7;
				detail.NumberOfWinners = this.Award7NumberOfWinners;
				detail.MoneyPerWinner = this.Award7MoneyPerWinner;
				details.Add(detail);
			}

			return details;
		}

		public void SetWinningDetails(List<WinningDetail> details)
		{
			foreach (var detail in details)
			{
				switch (detail.Serial)
				{
 					case 1:
						this.Award1Name = detail.Award;
						this.Award1NumberOfWinners = detail.NumberOfWinners;
						this.Award1MoneyPerWinner = detail.MoneyPerWinner;
						break;
					case 2:
						this.Award2Name = detail.Award;
						this.Award2NumberOfWinners = detail.NumberOfWinners;
						this.Award2MoneyPerWinner = detail.MoneyPerWinner;
						break;
					case 3:
						this.Award3Name = detail.Award;
						this.Award3NumberOfWinners = detail.NumberOfWinners;
						this.Award3MoneyPerWinner = detail.MoneyPerWinner;
						break;
					case 4:
						this.Award4Name = detail.Award;
						this.Award4NumberOfWinners = detail.NumberOfWinners;
						this.Award4MoneyPerWinner = detail.MoneyPerWinner;
						break;
					case 5:
						this.Award5Name = detail.Award;
						this.Award5NumberOfWinners = detail.NumberOfWinners;
						this.Award5MoneyPerWinner = detail.MoneyPerWinner;
						break;
					case 6:
						this.Award6Name = detail.Award;
						this.Award6NumberOfWinners = detail.NumberOfWinners;
						this.Award6MoneyPerWinner = detail.MoneyPerWinner;
						break;
					case 7:
						this.Award7Name = detail.Award;
						this.Award7NumberOfWinners = detail.NumberOfWinners;
						this.Award7MoneyPerWinner = detail.MoneyPerWinner;
						break;
				}
			}
		}
	}
}